﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections.Generic;

public partial class _Default : System.Web.UI.Page 
{
    private DataBaseAccess GetDataBaseAccess()
    {
        ConnectionStringSettings setting = ConfigurationManager.ConnectionStrings["DatabaseConnectionString1"];
        //Console.WriteLine("接続文字列:" + setting.ConnectionString);
        //Console.WriteLine("プロバイダ名:" + setting.ProviderName);

        return new DataBaseAccess(setting.ConnectionString);
    }

    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        DataBaseAccess dba = GetDataBaseAccess();
        dba.DeleteAll();
        //SqlDataSource1.DataBind();
        GridView1.DataBind();
    }
    protected void Button2_Click(object sender, EventArgs e)
    {
        DataBaseAccess dba = GetDataBaseAccess();
        List<WebService.KMessage> outList;
        dba.ReadLog(DateTime.Now.Subtract(new TimeSpan(24,0,0)), "default", out outList);
        TextBox1.Text = "";
        foreach (WebService.KMessage km in outList)
        {
            TextBox1.Text += km.Time + "," + km.Group + "," + km.SenderName + "," + km.DestName + "," + km.Log + "\n"; 
        }
    }
    protected void Button3_Click(object sender, EventArgs e)
    {
        DataBaseAccess dba = GetDataBaseAccess();
        dba.WriteLog(DateTime.Now, "default", "test", "test", "test");
        //SqlDataSource1.DataBind();
        GridView1.DataBind();
    }

    protected void Button4_Click(object sender, EventArgs e)
    {
        DataBaseAccess dba = GetDataBaseAccess();
        int num;
        if (int.TryParse(TextBox2.Text, out num))
        {
            for (int i = 0; i < num; i++)
            {
                dba.WriteLog(DateTime.Now, "default-dummy", "test", "test", "test");
            }
        }
        //SqlDataSource1.DataBind();
        GridView1.DataBind();
       
    }

}
